package com.playball.lottery.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 比分工具类
 * 
 * @author Administrator
 * 
 */
public class ScoreUtil {
	/**
	 * 
	 * @param marketCode
	 *            彩种，中文代码字符串
	 * @return 数字代号
	 */
	public static int stringToNumber(String marketCode) {
		if (marketCode.equals("竞彩比分")) {
			return 0;
		} else if (marketCode.equals("竞彩足球")) {
			return 90;
		} else if (marketCode.equals("篮球比分")) {
			return 91;
		} else if (marketCode.equals("北京单场")) {
			return 45;
		} else {
			return 0;
		}
	}

	/**
	 * 移除重复list值
	 * 
	 * @param list
	 * @return
	 */
	public static List<String> removeDuplicateWithOrder(List<String> list) {
		HashSet<String> hashSet = new HashSet<String>();
		List<String> newlist = new ArrayList<String>();
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			String element = (String) iterator.next();
			if (hashSet.add(element)) {
				newlist.add(element);
			}
		}
		list.clear();
		list.addAll(newlist);
		return list;
	}

	/**
	 * 获取两个List的不同彩豆素
	 * 
	 * @param list1
	 * @param list2
	 * @return
	 */
	public static List<String> getDiffrent5(List<String> list1, List<String> list2) {
		// long st = System.nanoTime();
		List<String> diff = new ArrayList<String>();
		List<String> maxList = list1;
		List<String> minList = list2;
		if (list2.size() > list1.size()) {
			maxList = list2;
			minList = list1;
		}
		Map<String, Integer> map = new HashMap<String, Integer>(maxList.size());
		for (String string : maxList) {
			map.put(string, 1);
		}
		for (String string : minList) {
			if (map.get(string) != null) {
				map.put(string, 2);
				continue;
			}
			diff.add(string);
		}
		for (Map.Entry<String, Integer> entry : map.entrySet()) {
			if (entry.getValue() == 1) {
				diff.add(entry.getKey());
			}
		}
		// System.out.println("getDiffrent5 total times " + (System.nanoTime() -
		// st));
		return diff;

	}

	/***
	 * 转换list格式
	 * 
	 * @param list
	 * @return
	 */
	public static List<String> changeListGeshi(List<Map<String, Object>> list) {
		List<String> newlist = new ArrayList<String>();
		for (int j = 0; j < list.size(); j++) {
			Map<String, Object> fMap = list.get(j);
			// 赛事ID
			String fmatchID = String.valueOf(fMap.get("i1"));
			newlist.add(fmatchID);
		}
		return newlist;
	}

	/**
	 * 如果当前我的关注赛事服务器已经不再发送，且allDataList也不含有，就删除
	 */
	public static List<Map<String, Object>> checkAllDataContainFocus(List<Map<String, Object>> flist, List<String> kList) {
		List<Map<String, Object>> newlist = new ArrayList<Map<String, Object>>();
		if (flist != null && kList != null) {
			for (int i = 0; i < flist.size(); i++) {
				Map<String, Object> aMap = flist.get(i);
				String amatchID = String.valueOf(aMap.get("i1"));
				if (!kList.contains(amatchID)) {
					newlist.add(aMap);
				}
			}
		}
		return newlist;
	}

}
